/**
 * Created by kurong on 2021/9/13.
 */

//console.log("在控制台输出");

/*
 * 1. 变量 variable
 *
 * */

var age;
age = 10;
console.log("age=" + age);
var name = 'smith';

age = 'ten';
console.log("age=" + age);

var number = 2;
var price = 29.9;
var xiaoji = number * price;


/*字符串 转换成数值类型*/
age = '10'; // 确定了当前数据类型 为 string 字符串
console.log("age的类型：" + typeof(age));

// 转换成整数类型
var a1 = parseInt(age); // a1 : int
console.log("a1的类型：" + typeof(a1));

price = '29.9';
console.log("price的类型：" + typeof(price));

// 转换成float
price = parseFloat(price);
console.log("price的类型：" + typeof(price));

// 数组
var names = new Array('王震', '柏浩', '巴用鑫', '王勤来');

for (var i = 0; i < names.length; i++) {
    console.log(names[i]);
}

var cars = ['宝马', '奔驰', '沃尔沃'];

var person = {
    perName: 'smith',
    perAge: 20,
    perAddress: "苏州"
};

console.log("person name :" + person.perName);
console.log("person age :" + person.perAge);
console.log("person address :" + person.perAddress);

var pro1 = {
    proId: 3169434,
    proName: '心心相印消毒湿巾',
    proPrice: 19.9
};

var pro2 = {
    proId: 32832992,
    proName: '奥妙洗衣液',
    proPrice: 28
};

var pro3 = {
    proId: 18932932,
    proName: '科沃斯地宝',
    proPrice: 1999.9
};

var proArray1 = [pro1, pro2, pro3];

var proArray2 = [
    {
        proId: 3169434,
        proName: '心心相印消毒湿巾',
        proPrice: 19.9
    },
    {
        proId: 32832992,
        proName: '奥妙洗衣液',
        proPrice: 28
    },
    {
        proId: 18932932,
        proName: '科沃斯地宝',
        proPrice: 1999.9
    }
];

for (var i = 0; i < proArray1.length; i++) {
    console.log(proArray1[i]);
}

var x = false;
console.log("x的数据类型" + typeof(x));

// 调用函数
fun1();
fun2("smith", 20);
var sum = fun3(10, 20);

// 定义函数(方法)
function fun1() {
    console.log("fun1");
}

function fun2(name, age) {
    console.log("fun2 name:" + name + " ,age:" + age);
}

function fun3(a, b) {
    var sum = a + b;
    return sum;
}
